package org.lgiavedoni.android.franq.core.sync.imp;

import java.util.ArrayList;
import java.util.List;

import org.lgiavedoni.android.franq.core.dao.AbstractDAO;
import org.lgiavedoni.android.franq.core.dao.DaoObject;
import org.lgiavedoni.android.franq.core.sync.Synchronizable;

public class GenericDao extends AbstractDAO<DaoObject> {

	public static GenericDao inst = new GenericDao();

	private GenericDao() {
	}

	@Override
	public Class getObjectClass() {
		return DaoObject.class;
	}

	public Object getLast(Class clazz) {
		List<?> l = dbService.getAll(clazz);
		if (l != null && l.size() > 0)
			return l.get(l.size() - 1);
		return null;
	}

	public List<DaoObject> getAll(Class clazz) {
		return dbService.getAll(clazz);
	}

	public List<Synchronizable> getAllNoSyncronized(Class clazz) {
		List<Synchronizable> list = new ArrayList<Synchronizable>();
		for (DaoObject obj : getAll(clazz)) {
			if ((obj instanceof Synchronizable) && !((Synchronizable) obj).isSyncronized())
				list.add((Synchronizable) obj);
		}
		return list;
	}

}
